package RequestBuilder;

import Data.Criteria;
import com.freebase.api.Freebase;
import com.freebase.json.JSON;
import static com.freebase.json.JSON.o;
import static com.freebase.json.JSON.a;

public class RequestBuilderFreeBase implements RequestBuilder {

	private Request request = new Request();
	
	@Override
	public Request createRequest() {
	    Freebase freebase = Freebase.getFreebase();
	    JSON query = o(
	    		  "id", null,
	    		  "type", "/film/film",
	    		  "name", "Blade Runner",
	    		  "directed_by", a(o(
	    		    "id", null,
	    		    "name", null
	    		  ))
	    		);
	   // request.setRequest(query);
		return request;
	}

	@Override
	public Request addCriteria(Request request, Criteria criteria) {
		request.addCriteria(criteria);
		return request;
	}
	
	public static String testFreebase1() {
		Freebase freebase = Freebase.getFreebase();
	    JSON query = o(
	    		  "id", null,
	    		  "type", "/film/film",
	    		  "name", "Blade Runner",
	    		  "directed_by", a(o(
	    		    "id", null,
	    		    "name", null
	    		  ))
	    		);
	    JSON result = freebase.mqlread(query);
	    String director = result.get("result").get("directed_by").get(0).get("name").string();
	    return director;
	}
	
	public static String testFreebase2() {
		Freebase freebase = Freebase.getFreebase();
	    JSON query = o(
	    		  "id", null,
	    		  "type", "/film/film",
	    		  "name", "Blade Runner",
	    		  "directed_by", a(o(
	    		    "id", null,
	    		    "name", null
	    		  ))
	    		);
	    JSON result = freebase.mqlread(query);
	    String director = result.get("result").get("directed_by").get(0).get("name").string();
	    return director;
	}
	
}
